package com.qyhl.webtv.module_microvideo.shortvideo.user.fragment;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.microvideo.ShortVideoBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

import java.util.List;

public class ShortVideoUserModel implements ShortVideoUserContract.ShortVideoUserModel {
    private ShortVideoUserPresenter mPresenter;

    ShortVideoUserModel(ShortVideoUserPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getUserWorks(String phone, final String page, int type) {
        String url = "";
        if (type == 4) {  //用户列表
            url = VideoUrl.GET_SHORT_VIDEO_USER_LIST;
        } else {  //用户榜单
            url = VideoUrl.GET_SHORT_VIDEO_USER_RANK;
        }

        EasyHttp.get(url)
                .params("phone", phone)
                .params("page", page)
                .execute(new SimpleCallBack<List<ShortVideoBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<ShortVideoBean> shortVideoBeans) {
                        if (shortVideoBeans != null && shortVideoBeans.size() > 0) {
                            mPresenter.setData(shortVideoBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
        
    }
}
